package com.bristua.mall.admin.user.biz;

import com.bristua.mall.admin.user.dao.TUserAccountMapper;
import com.bristua.mall.admin.user.dao.TUserAdressMapper;
import com.bristua.mall.admin.user.dao.TUserBankMapper;
import com.bristua.mall.admin.user.dao.TUserMapper;
import com.bristua.mall.admin.user.model.TUser;
import com.bristua.mall.admin.user.model.TUserAccount;
import com.bristua.mall.admin.user.model.TUserAdress;
import com.bristua.mall.admin.user.model.TUserBank;
import com.bristua.mall.admin.user.model.condition.TUserAccountExample;
import com.bristua.mall.admin.user.model.condition.TUserAdressExample;
import com.bristua.mall.admin.user.model.condition.TUserBankExample;
import com.bristua.mall.admin.user.model.vo.QueryUserAdressVO;
import com.bristua.mall.admin.user.model.vo.QueryUserBankVO;
import com.bristua.mall.admin.user.model.vo.QueryUserDetailVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2019/4/2.
 */
@Service
public class QueryUserDetailBiz {
    @Resource
    private TUserMapper tUserMapper;

    @Resource
    private TUserAccountMapper tUserAccountMapper;

    @Resource
    private TUserBankMapper tUserBankMapper;

    @Resource
    private TUserAdressMapper tUserAdressMapper;

    public QueryUserDetailVO queryUserDetail(String userId){
        QueryUserDetailVO queryUserDetailVO = new QueryUserDetailVO();
        TUser tUser = tUserMapper.selectByPrimaryKey(userId);
        BeanUtils.copyProperties(tUser,queryUserDetailVO);

        TUserAccountExample tUserAccountExample = new TUserAccountExample();
        tUserAccountExample.createCriteria().andUserIdEqualTo(userId);
        List<TUserAccount> tUserAccounts = tUserAccountMapper.selectByExample(tUserAccountExample);
        if(tUserAccounts!=null && tUserAccounts.size()>0){
            TUserAccount tUserAccount = tUserAccounts.get(0);
            queryUserDetailVO.setUserIntegral(String.valueOf(tUserAccount.getUserIntegral()));
        }
        TUserBankExample tUserBankExample = new TUserBankExample();
        tUserBankExample.createCriteria().andUserIdEqualTo(userId);
        List<TUserBank> tUserBanks = tUserBankMapper.selectByExample(tUserBankExample);
        if(tUserBanks!=null && tUserBanks.size()>0){
            for(TUserBank tUserBank : tUserBanks){
                QueryUserBankVO queryUserBankVO = new QueryUserBankVO();
                BeanUtils.copyProperties(tUserBank,queryUserBankVO);
                queryUserDetailVO.getBanks().add(queryUserBankVO);
            }

        }

        TUserAdressExample tUserAdressExample = new TUserAdressExample();
        tUserAdressExample.createCriteria().andUserIdEqualTo(userId);
        List<TUserAdress> tUserAdresses = tUserAdressMapper.selectByExample(tUserAdressExample);
        if(tUserAdresses!=null && tUserAdresses.size()>0){
            for(TUserAdress tUserAdress : tUserAdresses){
                QueryUserAdressVO queryUserAdressVO = new QueryUserAdressVO();
                BeanUtils.copyProperties(tUserAdress,queryUserAdressVO);
                queryUserDetailVO.getAddress().add(queryUserAdressVO);
            }

        }

        return queryUserDetailVO;
    }
}
